home *** CD-ROM | disk | FTP | other *** search
/ Apple WWDC 1996 / WWDC96_1996 (CD).toast / Technology Materials / MacApp Release 10 / MacApp Release 10 - HD Ready / Examples / Calc / UCalc.h < prev    next >
Encoding:
Text File  |  1996-04-03  |  32.0 KB  |  1,181 lines  |  [TEXT/MPS ]

  1. // UCalc.h 
  2. // Copyright © 1986-96 by Apple Computer, Inc. All rights reserved.
  3.  
  4. // This MacApp sample implements a simple spreadsheet 
  5. // This version, created Christmas Day 1989 by Larry Tesler, uses
  6. // classes TPrimaryScroller and TSecondaryScroller in USynchScroller
  7. // [instead of defining its own TCalcScroller and four AutoScroll methods]
  8. // to achieve synchronous scrolling [instead of near-synchronous scrolling]
  9. // and to enable auto-scrolling during column resizing.
  10.  
  11. /*
  12.   Change History:
  13.         03/29/96    srf        GetPrintExtent/CalcViewPerPage returns a VRect
  14.          3/23/96    srf        TCalcTypingCommand::DoMakeTypingCommand takes a CStr2 now.
  15.          3/23/96    srf        TCalcTypingCommand::AddCharacter takes a CStr2 now.
  16.          3/18/96    srf        Made better use of TView calls that return CRect/VPoint/VRect
  17.           3/4/96    srf        Fix the alignment for structures written/read to disk to be
  18.                               compatible for both 68K and PPC versions. 
  19.           1/4/96    TWB        Get rid of TFileHandler. 
  20.           12/21/95    TWB        Remove SetupUndoMenu. 
  21.           ----- 3.3 -----
  22.           ----- 3.3b1 -----
  23.           07/31/95    srf        cPrintSelection is declared in MacApp now. 
  24.           6/28/95    TWB        Don't need to include ULoMem. 
  25.           3/28/95    TWB        Alphabetized the includes. 
  26.           3/13/95    TWB        Change Free methods to destructors. 
  27. */
  28.  
  29. #ifndef __UCALC__
  30. #define __UCALC__
  31.  
  32. // Calc
  33.  
  34. #ifndef __CALCUTILITIES__
  35. #include "CalcUtilities.h"
  36. #endif
  37.  
  38. // MacApp
  39.  
  40. #ifndef __MACAPPTYPES__
  41. #include "MacAppTypes.h"
  42. #endif
  43.  
  44. #ifndef __UADORNERS__
  45. #include "UAdorners.h"
  46. #endif
  47.  
  48. #ifndef __UAPPLEEVENTS__
  49. #include "UAppleEvents.h"
  50. #endif
  51.  
  52. #ifndef __UAPPLICATION__
  53. #include "UApplication.h"
  54. #endif
  55.  
  56. #ifndef __UASSOCIATION__
  57. #include "UAssociation.h"
  58. #endif
  59.  
  60. #ifndef __UBEHAVIOR__
  61. #include "UBehavior.h"
  62. #endif
  63.  
  64. #ifndef __UCLIPBOARDMGR__
  65. #include "UClipboardMgr.h"
  66. #endif
  67.  
  68. #ifndef __UCOMMAND__
  69. #include "UCommand.h"
  70. #endif
  71.  
  72. #ifndef __UCONTROL__
  73. #include "UControl.h"
  74. #endif
  75.  
  76. #ifndef __UDEPENDENCIES__
  77. #include "UDependencies.h"
  78. #endif
  79.  
  80. #ifndef __UDESIGNATOR__
  81. #include "UDesignator.h"
  82. #endif
  83.  
  84. #ifndef __UDOCUMENT__
  85. #include "UDocument.h"
  86. #endif
  87.  
  88. #ifndef __UEDITIONDOCUMENT__
  89. #include "UEditionDocument.h"
  90. #endif
  91.  
  92. #ifndef __UEVENT__
  93. #include "UEvent.h"
  94. #endif
  95.  
  96. #ifndef __UEVENTHANDLER__
  97. #include "UEventHandler.h"
  98. #endif
  99.  
  100. #ifndef __UFAILURE__
  101. #include "UFailure.h"
  102. #endif
  103.  
  104. #ifndef __UFILE__
  105. #include "UFile.h"
  106. #endif
  107.  
  108. #ifndef __UFILEBASEDDOCUMENT__
  109. #include "UFileBasedDocument.h"
  110. #endif
  111.  
  112. #ifndef __UGEOMETRY__
  113. #include "UGeometry.h"
  114. #endif
  115.  
  116. #ifndef __UGRABBERTRACKER__
  117. #include "UGrabberTracker.h"
  118. #endif
  119.  
  120. #ifndef __UGRIDVIEW__
  121. #include "UGridView.h"
  122. #endif
  123.  
  124. #ifndef __ULIST__
  125. #include "UList.h"
  126. #endif
  127.  
  128. #ifndef __UMACGLOBALS__
  129. #include "UMacAppGlobals.h"
  130. #endif
  131.  
  132. #ifndef __UMACAPPUTILITIES__
  133. #include "UMacAppUtilities.h"
  134. #endif
  135.  
  136. #ifndef __UMEMORY__
  137. #include "UMemory.h"
  138. #endif
  139.  
  140. #ifndef __UMENUMGR__
  141. #include "UMenuMgr.h"
  142. #endif
  143.  
  144. #ifndef __UOBJECT__
  145. #include "UObject.h"
  146. #endif
  147.  
  148. #ifndef __UPATCH__
  149. #include "UPatch.h"
  150. #endif
  151.  
  152. #ifndef __UPRINTHANDLER__
  153. #include "UPrintHandler.h"
  154. #endif
  155.  
  156. #ifndef __UPRINTING__
  157. #include "UPrinting.h"
  158. #endif
  159.  
  160. #ifndef __USCROLLER__
  161. #include "UScroller.h"
  162. #endif
  163.  
  164. #ifndef __USECTION__
  165. #include "USection.h"
  166. #endif
  167.  
  168. #ifndef __USTREAM__
  169. #include "UStream.h"
  170. #endif
  171.  
  172. #ifndef __USYNCHSCROLLER__
  173. #include "USynchScroller.h"
  174. #endif
  175.  
  176. #ifndef __UTECOMMANDS__
  177. #include "UTECommands.h"
  178. #endif
  179.  
  180. #ifndef __UTEVIEW__
  181. #include "UTEView.h"
  182. #endif
  183.  
  184. #ifndef __UVIEW__
  185. #include "UView.h"
  186. #endif
  187.  
  188. #ifndef __UWINDOW__
  189. #include "UWindow.h"
  190. #endif
  191.  
  192. // Toolbox
  193.  
  194. #ifndef __ALIASES__
  195. #include <Aliases.h>
  196. #endif
  197.  
  198. #ifndef __APPLEEVENTS__
  199. #include <AppleEvents.h>
  200. #endif
  201.  
  202. #ifndef __BALLOONS__
  203. #include <Balloons.h>
  204. #endif
  205.  
  206. #ifndef __CONTROLS__
  207. #include <Controls.h>
  208. #endif
  209.  
  210. #ifndef __DEVICES__
  211. #include <Devices.h>
  212. #endif
  213.  
  214. #ifndef __DIALOGS__
  215. #include <Dialogs.h>
  216. #endif
  217.  
  218. #ifndef __EDITIONS__
  219. #include <Editions.h>
  220. #endif
  221.  
  222. #ifndef __EVENTS__
  223. #include <Events.h>
  224. #endif
  225.  
  226. #ifndef __FILES__
  227. #include <Files.h>
  228. #endif
  229.  
  230. #ifndef __FONTS__
  231. #include <Fonts.h>
  232. #endif
  233.  
  234. #ifndef __FP__
  235. #include <fp.h>
  236. #endif
  237.  
  238. #ifndef __MEMORY__
  239. #include <Memory.h>
  240. #endif
  241.  
  242. #ifndef __MENUS__
  243. #include <Menus.h>
  244. #endif
  245.  
  246. #ifndef __OSUTILS__
  247. #include <OSUtils.h>
  248. #endif
  249.  
  250. #ifndef __PACKAGES__
  251. #include <Packages.h>
  252. #endif
  253.  
  254. #ifndef __QUICKDRAW__
  255. #include <Quickdraw.h>
  256. #endif
  257.  
  258. #ifndef __SCRAP__
  259. #include <Scrap.h>
  260. #endif
  261.  
  262. #ifndef __SEGLOAD__
  263. #include <SegLoad.h>
  264. #endif
  265.  
  266. #ifndef __TEXTEDIT__
  267. #include <TextEdit.h>
  268. #endif
  269.  
  270. #ifndef __TOOLUTILS__
  271. #include <ToolUtils.h>
  272. #endif
  273.  
  274. #ifndef __TRAPS__
  275. #include <Traps.h>
  276. #endif
  277.  
  278. #ifndef __WINDOWS__
  279. #include <Windows.h>
  280. #endif
  281.  
  282.  
  283. class TRow;
  284. class TRowsView;
  285. class TRowList;
  286. class CRowIterator;
  287. class TColumn;
  288. class TColumnsView;
  289. class TColumnList;
  290. class CColumnIterator;
  291. class TCell;
  292. class TCellList;
  293. class CCalcCellIterator;
  294. class CSelectedExistingCalcCellIterator;
  295.  
  296.  
  297. const short kMaxRows = 120;                        // Maximum row number (arbitrary)
  298.  
  299. typedef short RowNumber;                        // RANGE = 0..kMaxRows; Zero indicates no row. 
  300.  
  301. const short kMaxColumns = 64;                    // Maximum column number (arbitrary)
  302.  
  303. typedef short ColumnNumber;                        // RANGE = 0..kMaxColumns;
  304.  
  305. const short kMaxValueLength = 24;                // Max. length of a value as a CString 
  306.  
  307. const OSType kSignature = 'SS12';                // Application signature. 
  308. const OSType kFileType = 'SF12';                // Data file type. 
  309.  
  310. const int kCalcWindowType = 1001;                // Resource id of the spreadsheet window 
  311.  
  312. enum CalcMode
  313. {
  314.     kManual, kAutomatic
  315. };
  316.  
  317.  
  318. typedef double ValueType;
  319. typedef double DiskValueType;                    // extendeds are for internal use only
  320. typedef CStr31 ValueString;                        // This isn't exactly what it used to be
  321. // Should be constrained by kMaxValueLength!!!!!
  322.  
  323. typedef decform ValueFormat;                    // Have SANE display numeric values in decimal
  324.  
  325. enum KindOfCell
  326. {
  327.     kEmptyCell, kValueCell, kTextCell, kErrorCell
  328. };
  329.  
  330.  
  331. enum EvalResult
  332. {
  333.     kNoError, kMissingRightParen, kSelfReference, kErrorCellReference, kBadNumber, kIllegalCharacter, kBadCellReference, kGarbageAtEnd
  334. };
  335.  
  336.  
  337. enum TypeOfSelection
  338. {
  339.     kNoSelection, kCellSelection, kRowSelection, kColumnSelection, kAllSelection
  340. };
  341.  
  342.  
  343. enum TypeOfStyle
  344. {
  345.     kNoStyle, kGeneral, kDecimalStyle, kNoDecimal, kScientific, kUnknownStyle
  346. };
  347.  
  348.  
  349. enum TypeOfLine
  350. {
  351.     kNoLine,                                    // for DrawLine routine
  352.     kSolidLine, kBoldLine, kVDottedLine, kHDottedLine, kRowSeparator, kColumnSeparator
  353. };
  354.  
  355.  
  356. //============================================================================================
  357. // Data read from or written to disk files or exchanged via clip must be built to use the same
  358. // alignment. We choose to center on mac68K alignment. In your application you may choose any
  359. // data alignment that you wish, so long as both your PPC and 68K code agree on it.
  360. //============================================================================================
  361. #if PRAGMA_ALIGN_SUPPORTED
  362. #pragma options align=mac68k
  363. #endif
  364.  
  365. struct FormatRecord
  366. {
  367.     TypeOfStyle fStyle;
  368.     SignedByte fJustification;
  369.     char fDigits;
  370.     char fFontNumber;
  371.     char fFontSize;
  372.     Style fFontStyle;
  373. };
  374. typedef FormatRecord * FormatPtr;
  375.  
  376. struct CalcDocDiskInfo
  377. {
  378.     CRect dimensions;
  379.     short allocatedCells;
  380.     short allocatedRows;
  381.     short allocatedColumns;
  382.     RowNumber editRow;
  383.     ColumnNumber editColumn;
  384.     CalcMode calcMode;
  385.     TypeOfSelection selectionType;
  386. };
  387.  
  388. // Info about the document's rows
  389. struct RowDiskInfo
  390. {
  391.     short number;
  392. };
  393.  
  394. // Info about the document's columns
  395. struct ColumnDiskInfo
  396. {
  397.     FormatRecord format;
  398.     short number;
  399.     short width;
  400. };
  401.  
  402. // The document's cells 
  403. // row/column coordinate read/written separately
  404. struct CellDiskInfo
  405. {
  406.     CStr255 formula;
  407.     short noOfReferences;
  408.     DiskValueType value;
  409.     KindOfCell kind;
  410.     EvalResult error;
  411. };
  412.  
  413.  
  414. struct ScrapInfoRecord
  415. {
  416.     CRect selection;
  417.     short noOfCells;
  418. };
  419.  
  420. // row/column coordinate read/written separately 
  421. // cell length read/written separately 
  422. struct CellScrapInfo
  423. {
  424.     CStr255 formula;
  425.     FormatRecord format;
  426. };
  427.  
  428. #if PRAGMA_ALIGN_SUPPORTED
  429. #pragma options align=reset
  430. #endif
  431. //============================================================================================
  432. //============================================================================================
  433.  
  434.  
  435. const OSType kTextScrapType = 'TEXT';
  436. const OSType kCalcScrapType = 'CALC';
  437.  
  438. const short kCellWidth = 80;                    // default width of each cell 
  439. const short kCellHeight = 17;                    // default height of each cell 
  440. const short kCellHBorder = 2;                    // pixels separating cell contents from
  441. // left/right edge 
  442.  
  443. const short kCellFont = applFont;
  444. const short kCellFontSize = 10;
  445. const short kRowTitleWidth = 32;                // width of row titles 
  446. const short kColumnTitleHeight = 20;            // height of column titles 
  447. const short kTitlesFont = applFont;                // font for column/row titles 
  448. const short kTitlesFontSize = 10;                // font size for column/row titles 
  449.  
  450. const short kEntryFont = applFont;                // default font of cell contents 
  451. const short kEntryFontSize = 10;                // default font size of cell contents 
  452. const short kEntryHeight = 20;                    // height of the cell entry view 
  453.  
  454. const CalcMode kCalcMode = kAutomatic;            // default calculation mode 
  455. const Boolean kForceAutomatic = TRUE;            // force automatic calculation 
  456. const Boolean kUpdateDependencies = TRUE;        // set cell's dependents 
  457.  
  458. const short kDefaultJustification = teCenter;    // default cell justification 
  459. const short kNoJustification = 2;                // constant representing no justification 
  460.  
  461. const short kValuePrecision = 18;                // digits of precision in our values 
  462. const short kTELength = (80 * 5);                // number of characters in the text edit
  463. // field 
  464.  
  465. const short kCellsViewHelp = 128;
  466. const short kColsViewHelp = kCellsViewHelp;
  467. const short kRowsViewHelp = kCellsViewHelp;
  468.  
  469. // Command Constants 
  470.  
  471. const short cRecalculate = 401;
  472. const short cAutoCalc = 403;
  473. const short cManualCalc = 404;
  474. const short cGeneral = 501;
  475. const short cNoDecimal = 503;
  476. const short cDecimal = 504;
  477. const short cScientific = 505;
  478. const short cSystemJustify = 506;
  479. const short cForceLeftJustify = 507;
  480. const short cRightJustify = 508;
  481. const short cCenter = 509;
  482. const short cSelecting = 1000;
  483. const short cSizeColumn = 1001;
  484. const short cCutText = 1103;
  485. const short cCopyText = 1104;
  486. const short cClearText = 1106;
  487. const short cCutCells = 1203;
  488. const short cCopyCells = 1204;
  489. const short cClearCells = 1206;
  490. const short cStandardCut = 1303;
  491. const short cStandardCopy = 1304;
  492. const short cStandardClear = 1306;
  493.  
  494. const short mWidthChanged = 1002;
  495. const short mValueChanged = 1003;
  496.  
  497. // Cursor Resource ID's 
  498.  
  499. const short kColumnSizingCursor = 256;            // cursor for resizing a column 
  500. const short kRowSizingCursor = 257;                // cursor for resizing a row--UNUSED 
  501.  
  502.  
  503. //--------------------------------------------------------------------------------------------------
  504. void ReadCellCoordinate(TFile* aFile,
  505.                         RowNumber& r,
  506.                         ColumnNumber& c);
  507.  
  508.  
  509. //--------------------------------------------------------------------------------------------------
  510. // TCalcApplication:
  511. //--------------------------------------------------------------------------------------------------
  512.  
  513. class TCalcApplication : public TApplication
  514. {
  515.     MA_DECLARE_CLASS;
  516.  
  517. public:
  518.     virtual~ TCalcApplication();
  519.     // Destructor
  520.  
  521.     virtual void ICalcApplication();
  522.     // Initializes the Application 
  523.  
  524.     virtual void AboutToLoseControl(Boolean convertClipboard);// override 
  525.     // Override to reset Edit menu items for incoming DAs 
  526.  
  527.     virtual TDocument* DoMakeDocument(CommandNumber itsCommandNumber,
  528.                                       TFile* itsFile);// override 
  529.     // Launches a TCalcDocument 
  530.  
  531.     virtual TView* MakeViewForAlienClipboard();    // override 
  532.     // Handle data that was left in the Clipboard by forces outside the application 
  533.  
  534. };
  535.  
  536.  
  537. //--------------------------------------------------------------------------------------------------
  538. // Forward class declaration.
  539. //--------------------------------------------------------------------------------------------------
  540.  
  541. class TCellsView;
  542. class TEntryView;
  543. class TCoordView;
  544.  
  545.  
  546. //--------------------------------------------------------------------------------------------------
  547. // TCalcDocument:
  548. //--------------------------------------------------------------------------------------------------
  549.  
  550. class TCalcDocument : public TEditionDocument
  551. {
  552.     MA_DECLARE_CLASS;
  553.  
  554. public:
  555.     //------------------------------------------------------------------------------------
  556.     // Initialization and termination
  557.     //------------------------------------------------------------------------------------
  558.  
  559.     TCalcDocument();
  560.     // Put the document in a safely free-able state 
  561.  
  562.     virtual void ICalcDocument(TFile* itsFile,
  563.                                const CRect& dimensions);
  564.     // Initialize the document 
  565.  
  566.     virtual void DoInitialState();                // override 
  567.     // Initialize allocation counts 
  568.  
  569.     virtual void DoMakeViews(Boolean forPrinting);// override 
  570.     // Launch the views which are seen in the document's window 
  571.  
  572.     virtual~ TCalcDocument();                    // override 
  573.     // Free the document 
  574.  
  575.     virtual void DoToPublisher(TCell* theCell,
  576.                                TPublisher* aPublisher);
  577.  
  578.     virtual void FreeData();                    // override 
  579.     // Delete the cells, rows, and columns 
  580.  
  581.     //------------------------------------------------------------------------------------
  582.     // Filing OVERRIDES 
  583.     //------------------------------------------------------------------------------------
  584.  
  585.     virtual void DoNeedDiskSpace(TFile* itsFile,
  586.                                  long& dataForkBytes,
  587.                                  long& rsrcForkBytes);// override 
  588.     // Tells how many bytes of disk space will be required to store the
  589.     // data for the document in a file on disk
  590.  
  591.     virtual void DoRead(TFile* aFile,
  592.                         Boolean forPrinting);    // override 
  593.     // Reads in the data from the disk, when a document is Opened or Reverted 
  594.  
  595.     virtual void DoWrite(TFile* aFile,
  596.                          Boolean makingCopy);    // override 
  597.     // Writes the data to the disk, when a document is Saved 
  598.  
  599.     //------------------------------------------------------------------------------------
  600.     // Menu handling 
  601.     //------------------------------------------------------------------------------------
  602.  
  603.     virtual void DoSetupMenus();                // override 
  604.     // Enable menu commands 
  605.  
  606.     virtual void DoMenuCommand(CommandNumber aCommandNumber);// override 
  607.     // Handle menu commands 
  608.  
  609.     //------------------------------------------------------------------------------------
  610.     // Cell management 
  611.     //------------------------------------------------------------------------------------
  612.  
  613.     virtual void AddCell(TCell* theCell,
  614.                          RowNumber r,
  615.                          ColumnNumber c);
  616.     // Add the cell to the document 
  617.  
  618.     virtual Boolean CellExists(RowNumber r,
  619.                                ColumnNumber c);
  620.     // Is there a cell object at these coordinates? 
  621.  
  622.     virtual void DeleteCell(RowNumber r,
  623.                             ColumnNumber c);
  624.     // Mark the cell at the given coordinates as deleted 
  625.  
  626.     virtual Boolean IsExistingCell(TCell* aCell);
  627.  
  628.     virtual void EditCell();
  629.     // Change the formula of the cell being edited to the CString in the entry view 
  630.  
  631.     virtual void FreeCell(TCell* theCell);
  632.     // Free the specified cell object 
  633.  
  634.     virtual void FreeDeletedCells();
  635.     // Free each cell object that is marked deleted 
  636.  
  637.     virtual TCell* GetCell(RowNumber r,
  638.                            ColumnNumber c);
  639.     // Return the cell object for the given coordinates. 
  640.  
  641.     virtual TCell* GetExistingCell(RowNumber r,
  642.                                    ColumnNumber c);
  643.     // Return the cell object or NULL if no cell is allocated for the given coordinates. 
  644.  
  645.     virtual Boolean IsAutoCalc();
  646.     // Evaluates fCalcMode == kAutomatic 
  647.  
  648.     virtual void SetEntry(RowNumber r,
  649.                           ColumnNumber c);
  650.     // Set the text in the entry view to the formula in the cell at the given
  651.     // coordinates
  652.  
  653.     virtual void UndeleteCell(RowNumber r,
  654.                               ColumnNumber c);
  655.     // If there is a cell at the given coordinates, mark it undeleted 
  656.  
  657.     //------------------------------------------------------------------------------------
  658.     // Row management 
  659.     //------------------------------------------------------------------------------------
  660.  
  661.     virtual void AddRow(TRow* theRow);
  662.     // Add the row to the document 
  663.  
  664.     virtual TRow* GetRow(RowNumber r);
  665.  
  666.     virtual Boolean RowExists(RowNumber r);
  667.  
  668.     //------------------------------------------------------------------------------------
  669.     // Column management 
  670.     //------------------------------------------------------------------------------------
  671.  
  672.     virtual void AddColumn(TColumn* theColumn);
  673.     // Add the column to the document 
  674.  
  675.     virtual Boolean ColumnExists(ColumnNumber c);
  676.  
  677.     virtual TColumn* GetColumn(ColumnNumber c);
  678.  
  679.     //------------------------------------------------------------------------------------
  680.     // Ranges of cells 
  681.     //------------------------------------------------------------------------------------
  682.  
  683.     virtual Boolean CellInRange(short r,
  684.                                 short c,
  685.                                 CRect& range);
  686.     // Do the given coordinates fall within the range? 
  687.  
  688.     virtual void ConstrainToUsedCells(CRect& cellRange);
  689.     // Shrink the range of cells to exclude unallocated cells, if possible 
  690.  
  691.     virtual void DoRecalculate(Boolean forceAutomatic,
  692.                                Boolean setDependents);
  693.     // Recalculate all cells if fCalcMode == kAutomatic, otherwise just selected cells 
  694.  
  695.     //------------------------------------------------------------------------------------
  696.     // Edition Manager Support 
  697.     //------------------------------------------------------------------------------------
  698.  
  699.     virtual void SetUserSelection(TDesignator* newSelection);
  700.     // Sets the designator for the user selection (if any).
  701.  
  702.     virtual void UserSelectionChanged(TView* changedView);// override 
  703.  
  704.     virtual void DoWriteData(const OSType aScrapType,
  705.                              TDesignator* aDesignator,
  706.                              TStream* aStream);    // override 
  707.     // Given a designator and a stream, writes the designated data to the stream. 
  708.  
  709.     virtual void DoWritePrivateTypes(TDesignator* aDesignator,
  710.                                      TStream* aStream);
  711.     // called by DoWriteData if aScrapType == kCalcScrapType 
  712.  
  713.     virtual void DoReadData(const OSType aScrapType,
  714.                             TDesignator* aDesignator,
  715.                             TStream* aStream,
  716.                             long count);        // override 
  717.     // Given a designator and a stream, read the designated data from the stream. 
  718.  
  719.     virtual void DoReadPrivateTypes(TDesignator* aDesignator,
  720.                                     TStream* aStream);
  721.     // called by DoReadData if aScrapType == kCalcScrapType 
  722.  
  723.     virtual void DoReadTEXT(TDesignator* aDesignator,
  724.                             TStream* aStream,
  725.                             long length);
  726.     // called by DoReadData if aScrapType == 'TEXT' 
  727.  
  728.     virtual void AddPublisherDependency(TSection* aSection);
  729.     // Create a dependency between an publisher and its published cells.
  730.  
  731.     virtual void AddSectionAndBorder(TSection* aSection);
  732.     // if the section is a publisher, create a dependency between it and all
  733.     // published cells.
  734.  
  735.     virtual void DoPostMakeViews(Boolean forPrinting);
  736.     // Iterate over the sections and create the dependencies between a publishers
  737.     // and its published cells.
  738.  
  739.     virtual void DoAddBorder(TSection* aSection);
  740.     // creates a border for the given section
  741.  
  742.     virtual void DoDeleteBorder(TSection* aSection);
  743.     // deletes a border for the given section
  744.  
  745.     virtual void RevealSelection(TDesignator* aSelection);
  746.  
  747.     //------------------------------------------------------------------------------------
  748.     // data members
  749.     //------------------------------------------------------------------------------------
  750. public:
  751.     CRect fDimensions;                            // the document's dimensions
  752.  
  753.     CRect fInUseBounds;                            // the area of the document that is in use 
  754.  
  755.     TCellList* fCells;
  756.  
  757.     TStandardDependencySpace* fDependencies;
  758.  
  759.     TCell* fEditCell;                            // the cell being edited (the current selection)
  760.  
  761.     TRowList* fRows;
  762.  
  763.     TColumnList* fColumns;
  764.  
  765.     TCellsView* fCellsView;                        // the view of the cells themselves 
  766.  
  767.     TRowsView* fRowsView;                        // the view of the row numbers 
  768.  
  769.     TColumnsView* fColumnsView;                    // the view of the column letters 
  770.  
  771.     TEntryView* fEntryView;                        // the view for entering/editing cell values
  772.  
  773.     TCoordView* fCoordView;                        // the view that shows the selected cell's coordinates
  774.  
  775.     short fRowOffset;
  776.  
  777.     short fColumnOffset;
  778.  
  779.     short fAllocatedCells;                        // the number of allocated cells
  780.  
  781.     short fAllocatedRows;                        // the number of allocated rows
  782.  
  783.     short fAllocatedColumns;                    // the number of allocated columns 
  784.  
  785.     short fNoOfRows;                            // maximum number of rows 
  786.  
  787.     short fNoOfColumns;                            // maximum number of columns 
  788.  
  789.     RowNumber fEditRow;                            // the row of the cell being edited 
  790.  
  791.     ColumnNumber fEditColumn;                    // the column of the cell being edited 
  792.  
  793.     CalcMode fCalcMode;                            // Manual or Automatic recalculation 
  794.  
  795.     TypeOfSelection fSelectionType;
  796.  
  797.     Boolean fColumnIsSelected;                    // a column has been selected 
  798.  
  799. };
  800.  
  801.  
  802. //--------------------------------------------------------------------------------------------------
  803. // TCalcWindow:
  804. //--------------------------------------------------------------------------------------------------
  805.  
  806. class TCalcWindow : public TWindow
  807. {
  808.     MA_DECLARE_CLASS;
  809.  
  810. public:
  811.     virtual~ TCalcWindow();
  812.     // Destructor
  813.  
  814.     virtual void DoPostCreate(TDocument* itsDocument);
  815.  
  816.     virtual void Draw(const VRect& area);        // override 
  817.  
  818. };
  819.  
  820.  
  821. //--------------------------------------------------------------------------------------------------
  822. // TCellsView is the view used to show the cell values. 
  823. //--------------------------------------------------------------------------------------------------
  824.  
  825. class TCellsView : public TTextGridView
  826. {
  827.     MA_DECLARE_CLASS;
  828.  
  829. public:
  830.  
  831.     virtual~ TCellsView();
  832.     // Destructor
  833.  
  834.     virtual void CreatePublisherAdorner(TPublisher* aPublisher);
  835.  
  836.     virtual void CreateSubscriberAdorner(TSubscriber* aSubscriber);
  837.  
  838.     virtual void ComputeBorderRgn(RgnHandle itsBorderRegion,
  839.                                   RgnHandle itsDesignation);
  840.  
  841.     //--------------------------------------------------------------------------------------------------
  842.     // Initialization and termination 
  843.     //--------------------------------------------------------------------------------------------------
  844.  
  845.     virtual void ICellsView(TCalcDocument* itsDocument,
  846.                             Boolean forClipboard,
  847.                             TView* itsParent);
  848.     // Initialize the view 
  849.  
  850.     virtual void DoPostCreate(TDocument* itsDocument);
  851.  
  852.     //--------------------------------------------------------------------------------------------------
  853.     // Commands and menus 
  854.     //--------------------------------------------------------------------------------------------------
  855.  
  856.     virtual void DoMouseCommand(VPoint& theMouse,
  857.                                 TToolboxEvent* event,
  858.                                 CPoint hysteresis);// override 
  859.  
  860.     virtual void DoSetupMenus();                // override 
  861.  
  862.     virtual void DoMenuCommand(CommandNumber aCommandNumber);// override 
  863.     // Handle menu commands 
  864.  
  865.     virtual void DoKeyEvent(TToolboxEvent* event);// override 
  866.  
  867.     //--------------------------------------------------------------------------------------------------
  868.     // Display and Selection 
  869.     //--------------------------------------------------------------------------------------------------
  870.  
  871.     virtual void AdornCol(short aCol,
  872.                           const VRect& area);    // override 
  873.     // Draw a column delimiter ("adornment") in the given area 
  874.  
  875.     virtual void AdornRow(short aCol,
  876.                           const VRect& area);    // override 
  877.     // Draw a row delimiter in the given area 
  878.  
  879.     virtual Handle DesignatorAsTEXT(TDesignator* aDesignator);
  880.  
  881.     virtual Boolean DoIdle(IdlePhase phase);    // override 
  882.     // Checks the state of the option key and decides whether to make the cursor
  883.     // need to be reset.  We used to use gAlwaysTrackCursor, but this is better.
  884.  
  885.     virtual void DoSetCursor(const VPoint& localPoint,
  886.                              RgnHandle cursorRegion);// override 
  887.  
  888.     virtual void DrawCell(GridCell aCell,
  889.                           const VRect& aRect);    // override 
  890.     // Draw the cell's value, using the proper justification 
  891.  
  892.     virtual CRect GetVisibleCells();
  893.     // Return a rectangle giving the cells that are visible 
  894.  
  895.     virtual Boolean IsCellVisible(GridCell aCell);
  896.     // Tell whether the specified cell is visible or not 
  897.  
  898.     virtual void PositionAtCell(GridCell aCell);
  899.     // Redraw the views so that aCell is at the top left corner of the grid 
  900.  
  901.     virtual void ReSelect(RgnHandle cellRegion);
  902.     // Set the current selection to the given cells 
  903.  
  904.     virtual void ReSelectCell(GridCell aCell);
  905.     // Set the current selection to the given cell 
  906.  
  907.     virtual void ScrollSelectionIntoView(Boolean redraw);// override 
  908.     // Scroll so that at least the top left cell of the selection is visible 
  909.  
  910.     virtual void SetCell(GridCell aCell);
  911.  
  912.     virtual void SetColWidth(short aCol,
  913.                              short numOfCols,
  914.                              short aWidth);        // override 
  915.  
  916.     virtual void SetSelection(RgnHandle cellsToSelect,
  917.                               Boolean extendSelection,
  918.                               Boolean highlight,
  919.                               Boolean select);    // override 
  920.     // Set the current selections to the specified cells. Adjust the entry and
  921.     // coordinate views accordingly.
  922.  
  923.     virtual void UserSelectionChanged(TView* changedView);
  924.     // invalidate all publisher/subscriber adorners when the user selection changes
  925.  
  926.     //--------------------------------------------------------------------------------------------------
  927.     // Printing OVERRIDES 
  928.     //--------------------------------------------------------------------------------------------------
  929.  
  930.     virtual VCoordinate DoBreakFollowing(VHSelect vhs,
  931.                                          VCoordinate previousBreak,
  932.                                          Boolean& Automatic);// override 
  933.  
  934.     virtual VRect GetPrintExtent();// override 
  935.     // Return the area to print, depending on whether the command was Print Selection
  936.     // or Print.
  937.  
  938.     //--------------------------------------------------------------------------------------------------
  939.     // Clipboard handling 
  940.     //--------------------------------------------------------------------------------------------------
  941.  
  942.     virtual Boolean ContainsClipType(ResType aType);// override 
  943.  
  944.     virtual void WriteCalcScrap(Handle calcScrap);
  945.  
  946.     virtual void WriteTextScrap(Handle textScrap);
  947.  
  948.     virtual void WriteToDeskScrap();            // override 
  949.  
  950. #if qDebug
  951.     virtual void DoDrawPageBreak(VHSelect vhs,
  952.                                  short whichBreak,
  953.                                  VCoordinate loc,
  954.                                  Boolean Automatic);// override 
  955.     // For debugging printing only, draw lines showing the page breaks. 
  956. #endif
  957.  
  958.     //------------------------------------------------------------------------------------
  959.     // data members
  960.     //------------------------------------------------------------------------------------
  961. public:
  962.     TCalcDocument* fCalcDocument;
  963.  
  964.     Boolean fLastOptionKey;                        // true if option key down at last idle.
  965.     // helps in tracking modifier keys for views
  966.     // that care. 
  967.  
  968. };
  969.  
  970.  
  971. //--------------------------------------------------------------------------------------------------
  972. // TCalcPrintHandler 
  973. //--------------------------------------------------------------------------------------------------
  974.  
  975. class TCalcPrintHandler : public TStdPrintHandler
  976. {
  977.     MA_DECLARE_CLASS;
  978.  
  979. public:
  980.  
  981.     virtual~ TCalcPrintHandler();
  982.     // Destructor
  983.  
  984.     virtual VPoint CalcViewPerPage();// override 
  985.  
  986.     virtual void DoMenuCommand(CommandNumber aCommandNumber);// override 
  987.     // Overridden to handle Print Selection. 
  988.  
  989.     virtual void DoSetupMenus();                // override 
  990.     // Overridden to handle Print Selection. 
  991.  
  992.     //------------------------------------------------------------------------------------
  993.     // data members
  994.     //------------------------------------------------------------------------------------
  995. public:
  996.     CommandNumber fCmdNumber;
  997.  
  998. };
  999.  
  1000.  
  1001. //--------------------------------------------------------------------------------------------------
  1002. // TEntryView uses TextEdit to display and edit the selected cell's formula. 
  1003. //--------------------------------------------------------------------------------------------------
  1004.  
  1005. class TEntryView : public TTEView
  1006. {
  1007.     MA_DECLARE_CLASS;
  1008.  
  1009. public:
  1010.  
  1011.     virtual~ TEntryView();
  1012.     // Destructor
  1013.  
  1014.     virtual void DoPostCreate(TDocument* itsDocument);
  1015.  
  1016.     virtual void DoKeyEvent(TToolboxEvent* event);// override 
  1017.  
  1018.     virtual TTETypingCommand* DoMakeTypingCommand(const CStr2& ch);// override 
  1019.     // Actually returns a TCalcTypingCommand 
  1020.  
  1021.     virtual void DoMouseCommand(VPoint& theMouse,
  1022.                                 TToolboxEvent* event,
  1023.                                 CPoint hysteresis);// override 
  1024.  
  1025.     virtual void DoMenuCommand(CommandNumber aCommandNumber);// override
  1026.  
  1027.     virtual void DoSetupMenus();                // override 
  1028.  
  1029.     //    virtual void SetupUndoMenu(); // override
  1030.  
  1031.     virtual void Draw(const VRect& area);        // override 
  1032.  
  1033.     virtual Boolean WantsToBeTarget();            // override 
  1034.  
  1035.     virtual void EditMode(Boolean editing);
  1036.     // Enter or leave TextEdit mode.  In TextEdit mode (fTEditing==true),
  1037.     // the Undo command causes an undo of the latest TextEdit action;
  1038.     // in non-TextEdit mode, Undo brings back the previous CString (fOldString)
  1039.  
  1040.     virtual void GetAsString(CStr255& theString);
  1041.     // Return the current text as a CString 
  1042.  
  1043.     virtual void SetActive(Boolean state);        // Override 
  1044.  
  1045.     virtual void SetEditMode();
  1046.     // Enter TextEdit mode and clear the current text 
  1047.  
  1048.     virtual void SetToString(const CStr255& theString);
  1049.     // Set the current text to theString 
  1050.  
  1051.     virtual void SwapStrings();
  1052.     // Exchange the current text with that saved in fOldString 
  1053.  
  1054.     //------------------------------------------------------------------------------------
  1055.     // data members
  1056.     //------------------------------------------------------------------------------------
  1057. public:
  1058.     CStr255 fOldString;                            // previous CString, for undo/redo 
  1059.  
  1060.     TCalcDocument* fCalcDocument;
  1061.  
  1062.     Boolean fTouched;
  1063.  
  1064.     Boolean fTEditing;                            // true: TextEdit mode 
  1065.  
  1066.     Boolean fFirstEdit;                            // true: undo to previous CString 
  1067.  
  1068. };
  1069.  
  1070.  
  1071. //--------------------------------------------------------------------------------------------------
  1072. // TCoordView is the view used to display the coordinates of the cell which is currently selected.
  1073. //--------------------------------------------------------------------------------------------------
  1074.  
  1075. class TCoordView : public TView
  1076. {
  1077.     MA_DECLARE_CLASS;
  1078.  
  1079. public:
  1080.  
  1081.     virtual~ TCoordView();
  1082.     // Destructor
  1083.  
  1084.     virtual void DoPostCreate(TDocument* itsDocument);
  1085.  
  1086.     virtual void Draw(const VRect& area);        // override 
  1087.     // Draws the view seen in the window.  Every nonblank view MUST override this method 
  1088.  
  1089.     //------------------------------------------------------------------------------------
  1090.     // data members
  1091.     //------------------------------------------------------------------------------------
  1092. public:
  1093.     TCalcDocument* fCalcDocument;
  1094.  
  1095. };
  1096.  
  1097.  
  1098. //--------------------------------------------------------------------------------------------------
  1099. // TCalcSelectCommand is a command object created to handle mouse movement when you
  1100. // click in a TCellsView.
  1101. //--------------------------------------------------------------------------------------------------
  1102.  
  1103. class TCalcSelectCommand : public TCellSelectCommand
  1104. {
  1105.     MA_DECLARE_CLASS;
  1106.  
  1107. public:
  1108.  
  1109.     virtual~ TCalcSelectCommand();
  1110.     // Destructor
  1111.  
  1112.     virtual void ICalcSelectCommand(TCalcDocument* itsDocument,
  1113.                                     TGridView* itsView,
  1114.                                     VPoint& theMouse,
  1115.                                     Boolean theShiftKey,
  1116.                                     Boolean theCommandKey);
  1117.  
  1118.     virtual void ComputeNewSelection(GridCell& clickedCell);// override 
  1119.  
  1120.     //------------------------------------------------------------------------------------
  1121.     // data members
  1122.     //------------------------------------------------------------------------------------
  1123. public:
  1124.     TCalcDocument* fCalcDocument;
  1125.  
  1126. };
  1127.  
  1128.  
  1129. //--------------------------------------------------------------------------------------------------
  1130. // TCalcTypingCommand: We define our own typing command in order to remember which cell the
  1131. // typing was performed in. Then if the user makes another selection we can undo/redo the
  1132. // correct cell.
  1133. //--------------------------------------------------------------------------------------------------
  1134.  
  1135. class TCalcTypingCommand : public TTETypingCommand
  1136. {
  1137.     MA_DECLARE_CLASS;
  1138.  
  1139. public:
  1140.     virtual~ TCalcTypingCommand();
  1141.     // Destructor
  1142.  
  1143.     virtual void ICalcTypingCommand(TTEView* itsTEView,
  1144.                                     const CStr2& itsFirstChar);// override 
  1145.     // Initialize the command object. Save the current cell selection for later Undo/Redo
  1146.  
  1147.     virtual void AddCharacter(const CStr2& ch);        // override 
  1148.     // Overridden to keep text visible when it overflows the entry view's box 
  1149.  
  1150.     virtual void UndoIt();                        // override 
  1151.     // Undo the typing in the target cell 
  1152.  
  1153.     virtual void RedoIt();                        // override 
  1154.     // Redo the typing in the target cell 
  1155.  
  1156.     //------------------------------------------------------------------------------------
  1157.     // data members
  1158.     //------------------------------------------------------------------------------------
  1159. public:
  1160.     TCellsView* fCellsView;
  1161.  
  1162.     GridCell fTargetCell;                        // cell selected when command was created 
  1163.  
  1164. };
  1165.  
  1166. //----------------------------------------------------------------------------------------
  1167. // Globals defined by this unit
  1168. //----------------------------------------------------------------------------------------
  1169.  
  1170. extern ValueFormat gGeneralFormat;                // SANE conversion formats 
  1171. extern ValueFormat gDecimalFormat;
  1172. extern ValueFormat gNoDecimalFormat;
  1173. extern ValueFormat gScientificFormat;
  1174. extern ValueFormat gNoFormat;
  1175. extern FormatRecord gDefaultFormat;                // default cell format 
  1176.  
  1177. extern Pattern gColumnSeparatorPattern;            // patterns for separator lines 
  1178. extern Pattern gRowSeparatorPattern;
  1179.  
  1180. #endif
  1181.